package com.oneraku.service.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @Author: hui.ren@huberbuy.com
 * @Date: 2020/2/25 00:06
 */
@Data
public class BaseEntity<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    @TableId
    private String id;
    @TableField(exist = false)
    private Long size;
    @TableField(exist = false)
    private Long current;
    public <T> IPage page(){
        Page<T> page = new Page<T>();
        page.setSize(null == size? 20: size);
        page.setCurrent(null  == current? 1:current);
        return page;
    }
    public <T> IPage pageDesc(String column){
        Page<T> page = new Page<T>();
        page.setSize(null == size? 20: size);
        page.setCurrent(null  == current? 1:current);
        OrderItem orderItem = new OrderItem();
        orderItem.setAsc(false);
        orderItem.setColumn(column);
        page.setOrders(Collections.singletonList(orderItem));
        return page;
    }
    public <T> IPage pageCreateTimeDesc(){
        Page<T> page = new Page<T>();
        page.setSize(null == size? 20: size);
        page.setCurrent(null  == current? 1:current);
        OrderItem orderItem = new OrderItem();
        orderItem.setAsc(false);
        orderItem.setColumn("create_time");
        page.setOrders(Collections.singletonList(orderItem));
        return page;
    }
}
